package com.seven.service;

import java.util.List;

import com.seven.dao.WorkerDao;
import com.seven.entity.Worker;

//员工业务类
public class WorkerService {

	WorkerDao workerDao = new WorkerDao();
	
	/**
	 * 添加员工
	 */
	public int addWorker(Worker worker) {
		return workerDao.addWorker(worker);
	}
	
	/**
	 * 更新员工
	 */
	public int updateWorker(Worker worker) {
		return workerDao.updateWorker(worker);
		
	}
	
	
	/**
	 * 更改员工状态为忙碌
	 */
	public int setWorker_state(Worker worker) {
		return workerDao.setWorker_state(worker);
		
	}
	
	/**
	 * 给员工加工分修改状态为空闲
	 */
	public int addScoreSetstare(Worker worker) {
			
		
		int worker_id = worker.getWorker_id();
		
		List<Worker> list = workerDao.selectByWorker_id(worker);
		Worker worker2 = list.get(0);
		
		int worker_score = worker2.getWorker_score()+1;
		String worker_name = worker2.getWorker_name();
		String worker_password = worker2.getWorker_password();
		int worker_state = 0;
		String worker_username = worker2.getWorker_username();
		
		Worker worker3 = new Worker();
		worker3.setWorker_id(worker_id);
		worker3.setWorker_name(worker_name);
		worker3.setWorker_password(worker_password);
		worker3.setWorker_score(worker_score);
		worker3.setWorker_state(worker_state);
		worker3.setWorker_username(worker_username);
		
		System.out.println(worker3+"3333333333333333333333333333aaa 33333333333333333333");
		
		int n = workerDao.updateWorker(worker3);
			return n;
			
		}
	
	
	/**
	 * 删除员工
	 */
	public int deleteWorker(Worker worker) {
		return workerDao.deleteWorker(worker);
		
	}
	
	/**
	 * 查询所有员工
	 */
	public List<Worker> selectAllWorker() {
		return workerDao.selectAllWorker();
		
	}
	
	/**
	 * 通过员工id查询员工
	 */
	public List<Worker> selectByWorker_id(Worker worker) {
		return workerDao.selectByWorker_id(worker);
		
	}
	
	/**
	 * 通过员工姓名查询员工
	 */
	public List<Worker> selectByWorker_name(Worker worker) {
		return workerDao.selectByWorker_name(worker);
		
	}
	
	/**
	 * 通过员工账号查询员工
	 */
	public List<Worker> selectByWorker_username(Worker worker) {
		return workerDao.selectByWorker_username(worker);
		
	}
	
	/**
	 * 查询出空闲员工
	 */
	public List<Worker> selectByWorker_state0() {
		return workerDao.selectByWorker_state0();
		
	}
	
	/**
	 * 查询出忙碌员工
	 */
	public List<Worker> selectByWorker_state1() {
		return workerDao.selectByWorker_state1();
		
	}
	
	/**
	 * 通过id查询姓名
	 */
	public String selectNameById(int worker_id) {
		if (worker_id == 0) {
			return "";
		}else{
		List<Worker> list = workerDao.selectNameById(worker_id);
		Worker worker = list.get(0);
		return worker.getWorker_name();
		}
	}
}
